package com.erp.controller;


import cn.hutool.core.convert.Convert;
import com.erp.Utils.ResponseModel;
import com.erp.entityVo.MenuALLVo;
import com.erp.entityVo.MenuIndexDto;
import com.erp.entityVo.MyMenuVo;
import com.erp.security.dto.JwtUserDto;
import com.erp.service.MyMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author  CJ 
 * @since 2021-10-09
 */
@Controller
@RequestMapping("/api")
@Api(tags = "系统：菜单路由")
public class MyMenuController {
    @Resource
    private MyMenuService myMenuService;

    @GetMapping("getMenu")
    @ResponseBody
    @ApiOperation(value = "通过用户id获取菜单")
    public List<MenuIndexDto> getMenu(){
            //        获取用户信息
        JwtUserDto jwtUserDto = (JwtUserDto)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Integer userId = jwtUserDto.getMyUser().getUserId();
        return myMenuService.getMenu(Convert.toInt(userId));
    }

    @GetMapping("/403")
    public String error403(){
        return "error/403";
    }

    @GetMapping("/404")
    public String error404(){
        return "error/404";
    }

    @GetMapping("/500")
    public String error500(){
        return "error/500";
    }
    @GetMapping("/admin")
    public String admin(){
        return "index";
    }
}
